package cn.tannn.ops.quartz.controller;

import cn.tannn.jdevelops.annotations.web.mapping.PathRestController;
import cn.tannn.jdevelops.jpa.result.JpaPageResult;
import cn.tannn.jdevelops.result.response.ResultPageVO;
import cn.tannn.jdevelops.result.response.ResultVO;
import cn.tannn.ops.quartz.controller.pojo.QrtzClazzMetaPage;
import cn.tannn.ops.quartz.entity.QrtzClazzMetaEntity;
import cn.tannn.ops.quartz.service.QrtzClazzMetaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;


/**
 * 任务元数据
 *
 * @author <a href="https://t.tannn.cn/">tan</a>
 * @version V1.0
 * @date 2024/8/26 下午2:05
 */
@PathRestController("jobmeta")
@Tag(name = "任务元数据",description = "系统主动注册，人为不能干预")
@Slf4j
@RequiredArgsConstructor
public class QrtzClazzMetaController {

    private final QrtzClazzMetaService qrtzClazzMetaService;

    @Operation(summary = "分页查询任务元数据")
    @PostMapping("page")
    public ResultPageVO<QrtzClazzMetaEntity, JpaPageResult<QrtzClazzMetaEntity>> page(@RequestBody @Valid QrtzClazzMetaPage page) {
        Page<QrtzClazzMetaEntity> byBean = qrtzClazzMetaService.findPage(page, page.getPage());
        return ResultPageVO.success(JpaPageResult.toPage(byBean), "查询成功");
    }

    @Operation(summary = "任务元数据集合")
    @GetMapping("lists")
    public ResultVO<List<QrtzClazzMetaEntity>> lists() {
        List<QrtzClazzMetaEntity> finds = qrtzClazzMetaService.finds();
        return ResultVO.success(finds);
    }
}
